{include file="public/heder"/}
<header class="header" id="header">
    <a href="javascript:history.go(-1)" target=_self class="back">返回</a>
    <h1>注册</h1>
</header>
<!--header-end-->

<div class="container" id="container">

    <form  method="post" class="login-form" action="{:url('register')}" id="register" onSubmit="return check();"  >
        <div class="registered">
            <div class="field">
                <input id="phoneNumber" type="text" name="phoneNumber" class="username" placeholder="请输入你需要注册手机号" >
                <span id="msg" style="font-size: 12px;color:red"></span>
            </div>
            <div class="field">
                <input id="password" type="password" name="password" class="username" placeholder="请输入密码" >
                <span id="pwdmsg" style="font-size: 12px;color: red"></span>
            </div>
            <div class="field">
                <input id="passwords" type="password" name="passwords" class="username" placeholder="再次输入密码" >
                <span id="pwdsmsg" style="font-size: 12px;color: red"></span>
            </div>
            <div class="field">
                <input type="text" name="yzm" id="yzm" class="yzm" placeholder="请输入短信验证码"  maxlength="">
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" id="btn" value="免费获取验证码" style="width:120px;height: 20px;background-color: #929292" />
            </div>
                <span id="codemsg" style="font-size: 12px;color: red"></span>
        </div>
        <a href="{:url('loginOut')}" style="font-size: 12px;color: #737373">已有账号？请登录</a>
        <div class="next-step">
            <button type="submit"  class="submit-btn">注册</button>
        </div>
    </form>
    <script>
        $('#phoneNumber').blur(function () {
            $.post("{:url('checkPhone')}", {'Phon': $('#phoneNumber').val()}, function (data) {
                $('#msg').html(data);
            })
        })
            var phon = document.getElementById("phoneNumber");
            var pwd = document.getElementById("password");
            var pwds = document.getElementById("passwords");
            var code =document.getElementById('yzm');
            function check() {
                    if (phon.value == '') {
                        $('#msg').html('电话号码不能为空');
                        return false;
                    } else if (!(/^1[34578]\d{9}$/.test(phon.value))) {
                        $('#msg').html('电话号码非法');
                        return false;
                    } else if (pwd.value == '') {
                        $('#pwdmsg').html('密码不能为空');
                        return false;
                    } else if (!(/^[0-9a-zA-Z_#]{6,16}$/.test(pwd.value))) {
                        $('#pwdmsg').html('密码必须为6-16个字符的大小写字母，数字');
                        return false;
                    } else if (pwds.value == '') {
                        $('#pwdsmsg').html('确认密码不能为空');
                        return false;
                    } else if (pwd.value != pwds.value) {
                        $('#pwdsmsg').html('两次密码不一致');
                        return false;
                    } else if (code.value == '') {
                        $('#codemsg').html('验证码不能为空');
                        return false;
                    } else {
                        $('#msg').html('');
                        $('#pwdmsg').html('');
                        $('#pwdsmsg').html('');
                        $('#codemsg').html('');
                        return true;
                    }

            }
        //post传输数据触发短信发送
        $('#btn').click(function(){
            $.post("{:url('getMsg')}",{'Phone':$('#phoneNumber').val()},function(data){
                    }
            )
        })
        var wait=60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");
                o.value="免费获取验证码";
                wait = 60;
            } else {

                o.setAttribute("disabled", true);
                o.value="重新发送(" + wait + ")";
                wait--;
                setTimeout(function() {
                            time(o)
                        },
                        1000)
            }
        }
        document.getElementById("btn").onclick=function(){
            if(phon.value!="" && (/^1[34578]\d{9}$/.test(phon.value)) && pwd.value!="" && pwds.value!="" && pwd.value==pwds.value){
                time(this);
            }
            }
            //post传输数据



    </script>
</div>
<!--container-end-->
</body>
</html>